package com.hzcx.app.simplechat.ui.friend.dialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseDialog;
import com.hzcx.app.simplechat.ui.home.AddFriendFirstActivity;
import com.hzcx.app.simplechat.util.dp.DpUtils;

import butterknife.BindView;

/**
 * 首页更多弹窗
 */
public class FriendSortDialog extends BaseDialog {

    @BindView(R.id.tv_type_online)
    TextView tvTypeOnline;
    @BindView(R.id.tv_type_create)
    TextView tvTypeCreate;

    private OnFriendSortMenuListener listener;
    private int x;
    private int y;

    public FriendSortDialog(@NonNull Context context, OnFriendSortMenuListener listener) {
        this(context,DpUtils.dp2px(context, 20),DpUtils.dp2px(context, 90),listener);
    }

    public FriendSortDialog(@NonNull Context context,int x,int y, OnFriendSortMenuListener listener) {
        super(context);
        this.listener = listener;
        this.x=x;
        this.y=y;
    }

    @Override
    public int getLayout() {
        return R.layout.dialog_friend_sort;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        getWindow().setGravity(Gravity.TOP | Gravity.RIGHT);
        getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.x = x;
        params.y = y;
        getWindow().setAttributes(params);
    }

    @Override
    public void initData() {
        tvTypeOnline.setOnClickListener(view -> {
            if(listener!=null){
                listener.sortType(1);
            }
            dismiss();
        });

        tvTypeCreate.setOnClickListener(view -> {
            if(listener!=null){
                listener.sortType(2);
            }
            dismiss();
        });
    }

    public interface OnFriendSortMenuListener {
        void sortType(int type);
    }
}
